package com.vm.dao.mobile.impl;

import org.apache.log4j.Logger;

import com.vm.common.Page;
import com.vm.common.SqlConstant;
import com.vm.dao.BaseDAOImpl;
import com.vm.dao.mobile.base.ISmsDetailDao;
import com.vm.entity.SmsDetail;
import com.vm.log4j.CustomizeLog4j;

public class SmsDetailDaoImpl extends  BaseDAOImpl<SmsDetail, Integer> implements ISmsDetailDao {
	private static Logger log = CustomizeLog4j.getLogger(SmsDetailDaoImpl.class);
	
	public SmsDetailDaoImpl() {
		setEntityClass(SmsDetail.class);
	}
	
	/**
	 * 根据业务ID获取业务短信
	 * @param sectionId
	 * @param pageSize
	 * @param currentPage
	 * @return
	 */
	public Page<SmsDetail> getSmsByBusinessId(Integer businessId,Integer pageSize,Integer currentPage){
		Page<SmsDetail> page = null;
		String countHql = SqlConstant.getSmsCountbyBusinessIdSql();
		String hql = SqlConstant.getSmsByBusinessIdSql();
		Object[] params = new Object[]{businessId};
		try {
			page = this.page(hql, countHql, params, pageSize, currentPage);
		} catch (Exception e) {
			log.error("SmsDetailDaoImpl getSmsByBusinessId is error");
		}
		return page;
	}
	
	public Integer getSmsCountByBusinessId(Integer businessId){
		Integer count = 0;
		String countHql = SqlConstant.getSmsCountbyBusinessIdSql();
		Object[] params = new Object[]{businessId};
		try {
			count = this.getTotalCount(countHql, params);
		} catch (Exception e) {
			log.error("SmsDetailDaoImpl getSmsCountByBusinessId is error");
		}
		return count;
	}
}
